/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MergerUI.java
 *
 * Created on Jan 12, 2011, 6:02:33 AM
 */
package project.jpdftools.pdfconverter.ui;

import java.awt.Toolkit;
import java.util.logging.Level;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import project.jpdfexport.constants.JPDFConst.TYPE;
import project.jpdftools.constants.Const;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;
import project.jpdftools.other.JOpenFile;
import project.jpdftools.other.JTextPaneProperties;
import project.jpdftools.pdfconverter.Converter;
import project.jpdftools.pdfconverter.PdfToText;
import project.jpdftools.pdfconverter.TextToPdf;

/**
 *
 * @author Mido
 */
public class PDFConverterUI extends JFrame {

    private static boolean is_component_visible = false;
    private Converter convert_instance;

    /**
     * Creates new form MergerUI
     */
    public PDFConverterUI() {
        initComponents();

        // center the frame
        project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());

        // indicate that the frame is visible
        is_component_visible = true;
        // hide the advanced options panel
        p_advanced_options.setVisible(false);
        // select the default font from the list of fonts
        list_font_names.setSelectedValue(tp_preview_text.getFont().getName(), true);
        LoggerManager.getLogger().log(Level.INFO, "Frame shown \"{0}\".", "PDFConverterUI");
    }

    public static boolean IsComponentVisible() {
        return is_component_visible;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bt_convert = new javax.swing.JButton();
        bt_cancel = new javax.swing.JButton();
        p_all = new javax.swing.JPanel();
        p_advanced_options = new javax.swing.JPanel();
        rb_right_to_left = new javax.swing.JRadioButton();
        rb_left_to_right = new javax.swing.JRadioButton();
        rb_use_default_font = new javax.swing.JRadioButton();
        rb_use_this_font = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        p_font = new javax.swing.JPanel();
        p_preview = new javax.swing.JPanel();
        tp_preview_text = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        list_font_names = new javax.swing.JList(project.jpdftools.toolkit.Toolkit.getFontModel());
        p_basic_options = new javax.swing.JPanel();
        p_input = new javax.swing.JPanel();
        tf_input_file = new javax.swing.JTextField();
        bt_browse_convert_from = new javax.swing.JButton();
        p_properties = new javax.swing.JPanel();
        tf_title = new javax.swing.JTextField();
        l_subject = new javax.swing.JLabel();
        l_keywords = new javax.swing.JLabel();
        l_author = new javax.swing.JLabel();
        tf_subject = new javax.swing.JTextField();
        tf_author = new javax.swing.JTextField();
        l_title = new javax.swing.JLabel();
        tf_keywords = new javax.swing.JTextField();
        p_conversion_type = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        list_conversion_type = new javax.swing.JList();
        p_output = new javax.swing.JPanel();
        tf_output_file = new javax.swing.JTextField();
        browse_convert_to = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_CONVERT"));
        setIconImage(Toolkit.getDefaultToolkit().getImage("Data/Icons/Soft Scraps Icons/10.png"));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                PDFConverterUI.this.windowClosing(evt);
            }
        });

        bt_convert.setText(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CONVERT"));
        bt_convert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_convertActionPerformed(evt);
            }
        });

        bt_cancel.setText(LocalizationManager.getCurrent_resource().getString("CANCEL"));
        bt_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelActionPerformed(evt);
            }
        });

        p_advanced_options.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_ADVANCED_OPTIONS"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));
        p_advanced_options.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                p_advanced_optionsComponentHidden(evt);
            }
            public void componentShown(java.awt.event.ComponentEvent evt) {
                p_advanced_optionsComponentShown(evt);
            }
        });

        rb_right_to_left.setText(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_RIGHT_TO_LEFT"));
        rb_right_to_left.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_right_to_leftActionPerformed(evt);
            }
        });

        rb_left_to_right.setText(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_LEFT_TO_RIGHT"));
        rb_left_to_right.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_left_to_rightActionPerformed(evt);
            }
        });

        rb_use_default_font.setText(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_USE_DEFAULT_FONT"));
        rb_use_default_font.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_use_default_fontActionPerformed(evt);
            }
        });

        rb_use_this_font.setText(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_USE_THIS_FONT"));
        rb_use_this_font.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_use_this_fontActionPerformed(evt);
            }
        });

        p_preview.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("FONT_PANEL_L_PREVIEW"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        tp_preview_text.setEditable(false);
        tp_preview_text.setBorder(null);
        tp_preview_text.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
        tp_preview_text.setText("Sample نموذج");
        tp_preview_text.setOpaque(false);

        javax.swing.GroupLayout p_previewLayout = new javax.swing.GroupLayout(p_preview);
        p_preview.setLayout(p_previewLayout);
        p_previewLayout.setHorizontalGroup(
            p_previewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_previewLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(tp_preview_text, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                .addContainerGap())
        );
        p_previewLayout.setVerticalGroup(
            p_previewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, p_previewLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tp_preview_text, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                .addContainerGap())
        );

        list_font_names.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list_font_names.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                list_font_namesMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(list_font_names);

        javax.swing.GroupLayout p_fontLayout = new javax.swing.GroupLayout(p_font);
        p_font.setLayout(p_fontLayout);
        p_fontLayout.setHorizontalGroup(
            p_fontLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
            .addComponent(p_preview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        p_fontLayout.setVerticalGroup(
            p_fontLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_fontLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p_preview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout p_advanced_optionsLayout = new javax.swing.GroupLayout(p_advanced_options);
        p_advanced_options.setLayout(p_advanced_optionsLayout);
        p_advanced_optionsLayout.setHorizontalGroup(
            p_advanced_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_advanced_optionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_advanced_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(p_font, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(rb_use_this_font)
                    .addComponent(rb_use_default_font)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(rb_right_to_left)
                    .addComponent(rb_left_to_right))
                .addContainerGap())
        );
        p_advanced_optionsLayout.setVerticalGroup(
            p_advanced_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_advanced_optionsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rb_left_to_right)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rb_right_to_left)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rb_use_default_font)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rb_use_this_font)
                .addGap(3, 3, 3)
                .addComponent(p_font, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        p_input.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_INPUT_FILE_TITLE"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        tf_input_file.setEditable(false);
        tf_input_file.setOpaque(false);

        bt_browse_convert_from.setIcon(new ImageIcon("Data/Icons/Basic/Open-icon.png"));
        bt_browse_convert_from.setText(LocalizationManager.getCurrent_resource().getString("BROWSE"));
        bt_browse_convert_from.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_browse_convert_fromActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p_inputLayout = new javax.swing.GroupLayout(p_input);
        p_input.setLayout(p_inputLayout);
        p_inputLayout.setHorizontalGroup(
            p_inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, p_inputLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tf_input_file, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_browse_convert_from)
                .addContainerGap())
        );
        p_inputLayout.setVerticalGroup(
            p_inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_inputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_input_file, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_browse_convert_from))
                .addContainerGap())
        );

        p_properties.setBorder(javax.swing.BorderFactory.createTitledBorder(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_DOCUMENT_INFO_TITLE")));
        p_properties.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                p_propertiesComponentHidden(evt);
            }
        });

        l_subject.setText("Subject:");

        l_keywords.setText("Keywords:");

        l_author.setText("Author:");

        l_title.setText("Title:");

        javax.swing.GroupLayout p_propertiesLayout = new javax.swing.GroupLayout(p_properties);
        p_properties.setLayout(p_propertiesLayout);
        p_propertiesLayout.setHorizontalGroup(
            p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_propertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_title)
                    .addComponent(l_subject))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_title, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(tf_subject, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_author)
                    .addComponent(l_keywords))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tf_keywords)
                    .addComponent(tf_author, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
                .addContainerGap())
        );

        p_propertiesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tf_subject, tf_title});

        p_propertiesLayout.setVerticalGroup(
            p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_propertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(p_propertiesLayout.createSequentialGroup()
                        .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(l_title)
                            .addComponent(tf_title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l_author))
                        .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(p_propertiesLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(p_propertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                    .addComponent(tf_subject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(l_subject)))
                            .addGroup(p_propertiesLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(tf_keywords, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(p_propertiesLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(l_keywords)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        p_propertiesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tf_author, tf_keywords, tf_subject, tf_title});

        p_conversion_type.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CONVERSION_TYPE"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        list_conversion_type.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Microsoft Word Files (*.doc, *.docx) To PDF Files (*.pdf)", "Text Files (*.txt) To PDF Files (*.pdf)", "Rich Text Format Files (*.rtf) To PDF Files (*.pdf)", "Microsoft PowerPoint Files (*.ppt, *.pptx) To PDF Files (*.pdf)", "HTML Files (*.htm, *.html) To PDF Files (*.pdf)", "Microsoft Excel Files (*.xls, *.xlsx) To PDF Files (*.pdf)", "CHM Files (*.chm) To PDF Files (*.pdf)", "PDF Files (*.pdf) To Microsoft Word Files (*.doc, *.docx)", "PDF Files (*.pdf) To Text Files (*.txt)", "PDF Files (*.pdf) To Rich Text Format Files (*.rtf)", "PDF Files (*.pdf) To Microsoft PowerPoint Files (*.ppt, *.pptx)", "PDF Files (*.pdf) To HTML Files (*.htm, *.html)", "PDF Files (*.pdf) To Microsoft Excel Files (*.xls, *.xlsx)", "PDF Files (*.pdf) To CHM Files (*.chm)" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        list_conversion_type.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list_conversion_type.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                list_conversion_typeMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(list_conversion_type);

        javax.swing.GroupLayout p_conversion_typeLayout = new javax.swing.GroupLayout(p_conversion_type);
        p_conversion_type.setLayout(p_conversion_typeLayout);
        p_conversion_typeLayout.setHorizontalGroup(
            p_conversion_typeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_conversion_typeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
                .addContainerGap())
        );
        p_conversion_typeLayout.setVerticalGroup(
            p_conversion_typeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_conversion_typeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );

        p_output.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_OUTPUT_FILE_TITLE"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        tf_output_file.setEditable(false);
        tf_output_file.setOpaque(false);

        browse_convert_to.setIcon(new ImageIcon("Data/Icons/Basic/Open-icon.png"));
        browse_convert_to.setText(LocalizationManager.getCurrent_resource().getString("BROWSE"));
        browse_convert_to.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browse_convert_toActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p_outputLayout = new javax.swing.GroupLayout(p_output);
        p_output.setLayout(p_outputLayout);
        p_outputLayout.setHorizontalGroup(
            p_outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, p_outputLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tf_output_file, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(browse_convert_to)
                .addContainerGap())
        );
        p_outputLayout.setVerticalGroup(
            p_outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_outputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_output_file, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browse_convert_to))
                .addContainerGap())
        );

        javax.swing.GroupLayout p_basic_optionsLayout = new javax.swing.GroupLayout(p_basic_options);
        p_basic_options.setLayout(p_basic_optionsLayout);
        p_basic_optionsLayout.setHorizontalGroup(
            p_basic_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_basic_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(p_conversion_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(p_input, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(p_output, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(p_properties, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        p_basic_optionsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {p_conversion_type, p_input, p_output, p_properties});

        p_basic_optionsLayout.setVerticalGroup(
            p_basic_optionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_basic_optionsLayout.createSequentialGroup()
                .addComponent(p_conversion_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p_input, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p_output, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p_properties, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout p_allLayout = new javax.swing.GroupLayout(p_all);
        p_all.setLayout(p_allLayout);
        p_allLayout.setHorizontalGroup(
            p_allLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_allLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(p_basic_options, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p_advanced_options, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        p_allLayout.setVerticalGroup(
            p_allLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_allLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_allLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(p_advanced_options, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(p_basic_options, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(p_all, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(bt_convert)
                    .addGap(7, 7, 7)
                    .addComponent(bt_cancel)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(p_all, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_convert)
                    .addComponent(bt_cancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelActionPerformed
        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
        LoggerManager.getLogger().log(Level.INFO, "Frame hidden \"{0}\".", "PDFConverterUI");
    }//GEN-LAST:event_bt_cancelActionPerformed

    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
        bt_cancelActionPerformed(null);
    }//GEN-LAST:event_windowClosing

    private void bt_convertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_convertActionPerformed
        // check for valid inputs
        if (tf_input_file.getText().isEmpty() == true || tf_output_file.getText().isEmpty() == true
                || list_conversion_type.isSelectionEmpty() == true) {
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_MISSING_INPUTS"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }
        // perform the conversion operation
        if (convert_instance.convertFiles(Const.program_version, tf_title.getText(), tf_author.getText(), tf_subject.getText(),
                tf_keywords.getText(), project.jpdftools.toolkit.Toolkit.getFontPath(list_font_names.getSelectedValue().toString())) == true) {

            Object[] options = {LocalizationManager.getCurrent_resource().getString("OPEN_FILE"),
                LocalizationManager.getCurrent_resource().getString("DONT_OPEN_FILE")};

            // ask the user if he/she wants to open the merged file
            JOpenFile.showOptionDialog(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CONVERSION_SUCCESS"),
                    LocalizationManager.getCurrent_resource().getString("SUCCESS"), options, convert_instance.getDestination());
        } else {
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CONVERSION_ERROR"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
        }
    }//GEN-LAST:event_bt_convertActionPerformed

    private void list_conversion_typeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_list_conversion_typeMouseClicked
        int selected_index = list_conversion_type.getSelectedIndex();
        emptyFields();

        // intialize the convert_instance according to the selected index
        switch (selected_index) {
            case (1):
                convert_instance = new TextToPdf();
                break;
            case (8):
                convert_instance = new PdfToText();
                break;
        }
        // show/hide the advanced options panel
        p_advanced_options.setVisible(convert_instance.isUseAdvancedOptions());
        // show/hide the document info panel
        p_properties.setVisible(convert_instance.isUseDocumentInfo());

        // set language type
        if (convert_instance.getLanguageType() == TYPE.left_to_right) {
            rb_left_to_right.setSelected(true);
            rb_right_to_left.setSelected(false);
        } else {
            rb_right_to_left.setSelected(true);
            rb_left_to_right.setSelected(false);
        }

        // set default font state
        if (convert_instance.isUseDefaultFont() == true) {
            rb_use_default_font.setSelected(true);
            rb_use_this_font.setSelected(false);
            p_font.setVisible(false);
        } else {
            rb_use_default_font.setSelected(false);
            rb_use_this_font.setSelected(true);
            p_font.setVisible(true);
        }
    }//GEN-LAST:event_list_conversion_typeMouseClicked

    private void bt_browse_convert_fromActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_browse_convert_fromActionPerformed
        // return with error message if nothing is selected
        if (list_conversion_type.isSelectionEmpty() == true) {
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_NO_CONVERSION_SELECTED"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }
        // choose input file location
        JFileChooser file_chooser = new JFileChooser();
        file_chooser.setDialogTitle(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CHOOSE_INPUT_FILE_LOCATION"));
        file_chooser.setMultiSelectionEnabled(false);
        file_chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        file_chooser.setFileFilter(convert_instance.getSourceExtensionFilter());

        if (file_chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            // set the source file name in the text field
            tf_input_file.setText(file_chooser.getSelectedFile().getAbsolutePath());
            // set the source file name in the convert instance
            convert_instance.setSource(file_chooser.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_bt_browse_convert_fromActionPerformed

    private void browse_convert_toActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browse_convert_toActionPerformed
        // return with error message if nothing is selected
        if (list_conversion_type.isSelectionEmpty() == true) {
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("CONVERT_UI_NO_CONVERSION_SELECTED"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }
        // choose input file location
        JFileChooser file_chooser = new JFileChooser();
        file_chooser.setDialogTitle(LocalizationManager.getCurrent_resource().getString("CONVERT_UI_CHOOSE_OUTPUT_FILE_NAME"));

        if (file_chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            // set the source file name in the text field
            tf_output_file.setText(file_chooser.getSelectedFile().getAbsolutePath() + convert_instance.getDestinationExtension());
            // set the source file name in the convert instance
            convert_instance.setDestination(file_chooser.getSelectedFile().getAbsolutePath() + convert_instance.getDestinationExtension());
        }
    }//GEN-LAST:event_browse_convert_toActionPerformed

    private void list_font_namesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_list_font_namesMouseClicked
        // setAttributes the font style in the setAttributes panel
        new JTextPaneProperties(tp_preview_text, 36, list_font_names.getSelectedValue().toString()).setAttributes("Normal");
}//GEN-LAST:event_list_font_namesMouseClicked

    private void p_advanced_optionsComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_p_advanced_optionsComponentHidden
        this.setSize(p_all.getPreferredSize().width + 10, p_all.getPreferredSize().height + 60);
        // recenter the component in the middle of the screen
        project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());
    }//GEN-LAST:event_p_advanced_optionsComponentHidden

    private void p_advanced_optionsComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_p_advanced_optionsComponentShown
        p_advanced_optionsComponentHidden(evt);
    }//GEN-LAST:event_p_advanced_optionsComponentShown

    private void rb_left_to_rightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_left_to_rightActionPerformed
        if (rb_left_to_right.isSelected() == true) {
            convert_instance.setLanguageType(TYPE.left_to_right);
            rb_right_to_left.setSelected(false);
        } else {
            rb_left_to_right.setSelected(true);
        }
    }//GEN-LAST:event_rb_left_to_rightActionPerformed

    private void rb_right_to_leftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_right_to_leftActionPerformed
        if (rb_right_to_left.isSelected() == true) {
            convert_instance.setLanguageType(TYPE.right_to_left);
            rb_left_to_right.setSelected(false);
        } else {
            rb_right_to_left.setSelected(true);
        }
    }//GEN-LAST:event_rb_right_to_leftActionPerformed

    private void rb_use_default_fontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_use_default_fontActionPerformed
        if (rb_use_default_font.isSelected() == true) {
            p_font.setVisible(false);
            convert_instance.setUseDefaultFont(true);
            rb_use_this_font.setSelected(false);
        } else {
            rb_use_default_font.setSelected(true);
        }
    }//GEN-LAST:event_rb_use_default_fontActionPerformed

    private void rb_use_this_fontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_use_this_fontActionPerformed
        if (rb_use_this_font.isSelected() == true) {
            p_font.setVisible(true);
            convert_instance.setUseDefaultFont(false);
            rb_use_default_font.setSelected(false);
        } else {
            rb_use_this_font.setSelected(true);
        }
    }//GEN-LAST:event_rb_use_this_fontActionPerformed

    private void p_propertiesComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_p_propertiesComponentHidden
        this.setSize(p_all.getPreferredSize().width + 10, p_all.getPreferredSize().height + 60);
        // recenter the component in the middle of the screen
        project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());
    }//GEN-LAST:event_p_propertiesComponentHidden

    /**
     * Empties all the field in the frame
     */
    private void emptyFields() {
        tf_author.setText("");
        tf_input_file.setText("");
        tf_keywords.setText("");
        tf_output_file.setText("");
        tf_subject.setText("");
        tf_title.setText("");
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browse_convert_to;
    private javax.swing.JButton bt_browse_convert_from;
    private javax.swing.JButton bt_cancel;
    private javax.swing.JButton bt_convert;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel l_author;
    private javax.swing.JLabel l_keywords;
    private javax.swing.JLabel l_subject;
    private javax.swing.JLabel l_title;
    private javax.swing.JList list_conversion_type;
    private static javax.swing.JList list_font_names;
    private javax.swing.JPanel p_advanced_options;
    private javax.swing.JPanel p_all;
    private javax.swing.JPanel p_basic_options;
    private javax.swing.JPanel p_conversion_type;
    private javax.swing.JPanel p_font;
    private javax.swing.JPanel p_input;
    private javax.swing.JPanel p_output;
    private javax.swing.JPanel p_preview;
    private javax.swing.JPanel p_properties;
    private javax.swing.JRadioButton rb_left_to_right;
    private javax.swing.JRadioButton rb_right_to_left;
    private javax.swing.JRadioButton rb_use_default_font;
    private javax.swing.JRadioButton rb_use_this_font;
    private javax.swing.JTextField tf_author;
    private javax.swing.JTextField tf_input_file;
    private javax.swing.JTextField tf_keywords;
    private javax.swing.JTextField tf_output_file;
    private javax.swing.JTextField tf_subject;
    private javax.swing.JTextField tf_title;
    private javax.swing.JTextPane tp_preview_text;
    // End of variables declaration//GEN-END:variables
}
